package util;

import com.alibaba.druid.pool.DruidDataSourceFactory;

import javax.sql.DataSource;
import java.io.FileInputStream;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.util.Properties;
import java.util.Scanner;

/**
 * 删除笔记信息
 */
public class DeleteNote {
    public static void main(String[] args) throws Exception {
        Scanner s=new Scanner(System.in);
        System.out.print("请输入要删除的笔记编号：");
        int id = s.nextInt();
        //创建连接池
        Properties properties = new Properties();
        properties.load(new FileInputStream("D:\\study\\Java\\YuQue\\src\\druid.properties.properties"));
        //dataSource 就是连接池
        DataSource dataSource = DruidDataSourceFactory.createDataSource(properties);
        //获取连接
        Connection connection = dataSource.getConnection();
        //sql语句
        String str="DELETE FROM note WHERE id=?";
        //拉数据
        PreparedStatement preparedStatement = connection.prepareStatement(str);
        //给?赋值
        preparedStatement.setInt(1,id);
        //删除sql语句
        int i = preparedStatement.executeUpdate();
        if(i>0){
            System.out.println("删除成功");
        }else {
            System.out.println("删除失败");
        }
    }
}
